<?php
/**
 * Created by PhpStorm.
 * User: krystal
 * Date: 2019/6/17
 * Time: 17:40
 */

namespace app\common\validate;


use think\Validate;

class PhysicalStore extends Validate
{
    protected $rule = [
        'id' => 'require|gt:0',
        'oid' => 'require|gt:0',
        'trade_type' => 'require|number|in:1,2',
        'gid' => 'require|gt:0',
        'real_name' => 'require|chsAlphaNum|length:1,25',
        'telphone' => 'require|checkTel',
        'remark' => 'length:0,100',
        'address' => 'require',
        'num' => 'require|gt:0',
    ];

    protected $message = [
        'id.require' => '未知的商品',
        'id.gt' => '未知的商品',
        'oid.require' => '未知的订单',
        'oid.gt' => '未知的订单',
        'trade_type.require'=>'请选择支付方式',
        'trade_type.in'=>'未知的支付方式',
        'gid.require' => '未知的商品',
        'gid.gt' => '未知的商品',
        'real_name.require'=>'请填写名称',
        'real_name.chsAlphaNum'=>'名称只可以是汉字,字母等组成',
        'real_name.length'=>'名称违规',
        'telphone.require'=>'请输入手机号',
        'telphone.checkTel'=>'手机号格式错误',
        'remark.length'=>'请填写一百字以内的备注',
        'address.require'=>'请填写地址',
        'num.require'=>'购买数量未知',
        'num.gt'=>'购买数量未知'
    ];

    protected $scene = [
        'goods_detail' => [
            'id'
        ],
        'pay_order' => [
            'trade_type',
            'gid',
            'real_name',
            'telphone',
            'address',
            'num'
        ],
        'order'=>[
            'oid'
        ],
    ];


    /**
     * 验证手机格式是否正确
     * @param $value
     * @return bool
     */
    public function checkTel($value)
    {
        if (preg_match("/^1[3456789]{1}\d{9}$/", $value)) {
            return true;
        } else {
            return false;
        }
    }
}